<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"; xmlns:th="http://www.thymeleaf.org" >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>URL LIST</title>
    <link th:href="@{/js/layui/css/layui.css}" rel="stylesheet"/>
    <script th:src="@{/js/layui/layui.js}"></script>
</head>

<body class="layui-layout-body">
    <!--<div class="layui-btn-group demoTable">
        <button class="layui-btn" data-type="getCheckData">获取选中行数据</button>
        <button class="layui-btn" data-type="getCheckLength">获取选中数目</button>
        <button class="layui-btn" data-type="isAll">验证是否全选</button>
    </div>-->
    <div class="layui-layout layui-layout-admin">
        <table id="urlListTable" lay-filter="test"></table>
    </div>
</body>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#urlListTable'
            ,height: 400
            ,url:'/url/queryUrlList'
            ,page: true
            ,cellMinWidth: 40
            ,cols: [
                [
                     {type: 'checkbox',fixed:'left'}
                    ,{field: 'id', title: 'ID', sort: true, fixed: 'left',width:80}
                    ,{field: 'code', title: '名称', }
                    ,{field: 'url', title: 'URL',  sort: true}
                    ,{field: 'remark', title: '备注'}
                    ,{field: 'isUsed', title: '是否可用'}
                    ,{field: 'splitter', title: '替换字段', sort: true}
                    ,{field: 'responseField', title: '拼装信息', sort: true}
                    ,{field: 'isSourceTemplate', title: '是否为数据源模板'}
                    ,{field: 'dataSource', title: '解析信息',  sort: true}
                    /*,{field: 'endPoint.id', title: '推送端ID', sort: true}
                    ,{field: 'endPoint.name', title: '推送端名称', sort: true}
                    ,{field: 'endPoint.url', title: '推送端URL', sort: true}*/
                    ,{fixed:'right',title:'操作',align:'center',toolbar:'#barDemo'}
                ]
            ]
        });

        //监听工具条
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
                layer.open({
                    type:2
                    ,title:'明细信息'
                    ,closeBtn:true
                    ,area: ['1200px','600px']
                    ,shade: 0.8
                    ,id:'Layer_URLDETAIL'
                    ,btn:['关闭']
                    ,btnAlign: 'c'
                    ,moveType: 1 //拖拽模式，0或者1
                    ,content: 'http://localhost:46318/url/form?id='+data.id
                    /*,success: function(layero){
                        var btn = layero.find('.layui-layer-btn');
                        btn.find('.layui-layer-btn0').attr({
                            href: 'http://www.layui.com/'
                            ,target: '_blank'
                        });
                    }*/
                })


            } else if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.alert('编辑行：<br>'+ JSON.stringify(data))
            }
        });

        var $ = layui.$, active = {
            getCheckData: function(){ //获取选中数据
                var checkStatus = table.checkStatus('urlListTable')
                    ,data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
            /*,getCheckLength: function(){ //获取选中数目
                var checkStatus = table.checkStatus('urlListTable')
                    ,data = checkStatus.data;
                layer.msg('选中了：'+ data.length + ' 个');
            }
            ,isAll: function(){ //验证是否全选
                var checkStatus = table.checkStatus('urlListTable');
                layer.msg(checkStatus.isAll ? '全选': '未全选')
            }*/
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });

</script>

</html>